/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-10-06 21:33:16
 * Last Modified: 2017-07-31 14:31:05
 * File Name: errorcode/errcode.go
 * Description:
 */
package errorcode

const (
	EC_GL_SUCCESS uint = 0

	EC_GL_INVALID_ACCESS_TOKEN uint = 403001
	EC_GL_INVALID_APPKEY       uint = 403002
	EC_GL_INVALID_IP           uint = 403003
	EC_GL_INVALID_URL_PARAMS   uint = 403007
	EC_GL_INVALID_URL_TIME     uint = 403004
	EC_GL_INVALID_URL_SIGN     uint = 403005
	EC_GL_INVALID_SERVICE      uint = 403006
	EC_GL_INVALID_SESSIONID    uint = 403007
	EC_GL_INVALID_HTTPS        uint = 403008

	EC_GL_INVALID_JSON_BODY uint = 404001

	EC_GL_INTERNAL_ERROR uint = 503001
)

const (
	EC_SERVICEPAGEINFO_GET_INVALID_VERSIONID uint = 201001 //请求参数中versionid不合法
	EC_SERVICEPAGEINFO_GET_INVALID_BODY      uint = 201002
	EC_SERVICEPAGEINFO_BODY_MISSING          uint = 201003
	EC_SERVICEPAGEINFO_DELETE_INVALID_SID    uint = 201004
	EC_SERVICEPAGEINFO_SID_MISSING           uint = 201005
	EC_SERVICEPAGEINFO_GET_MAX_VERSIONID_ERR uint = 201008
	EC_SERVICEPAGEINFO_NO_DATA_IN_DB         uint = 201009

	EC_INVALID_TICK            uint = 201006
	EC_HOTACTIVITY_AID_MISSING uint = 201007

	EC_HOTACTIVITY_ACTIVITYID_NOMATCH uint = 201010

	EC_ADVERTOPER_POSITION_INVALID uint = 201201

	EC_GL_INVAILD_ITEMPLAT_OR_STATUS_OR_POS_OR_EXPIRED uint = 202001
)

var (
	errorMsg map[uint]string
)

func init() {
	errorMsg = make(map[uint]string)

	errorMsg[EC_GL_SUCCESS] = "success"
	errorMsg[EC_GL_INVALID_ACCESS_TOKEN] = "invalid access_token"
	errorMsg[EC_GL_INVALID_APPKEY] = "invalid appkey"
	errorMsg[EC_GL_INVALID_IP] = "Not allowed IP source"
	errorMsg[EC_GL_INVALID_URL_PARAMS] = "invalid url params"
	errorMsg[EC_GL_INVALID_URL_TIME] = "invalid url time"
	errorMsg[EC_GL_INVALID_URL_SIGN] = "invalid url sign"
	errorMsg[EC_GL_INVALID_SERVICE] = "invalid sync service"
	errorMsg[EC_GL_INVALID_HTTPS] = "only https is allowed!"

	errorMsg[EC_GL_INVALID_JSON_BODY] = "invalid request josn body"

	errorMsg[EC_GL_INTERNAL_ERROR] = "internal server error"

	errorMsg[EC_SERVICEPAGEINFO_GET_INVALID_VERSIONID] = "invalid param versionid, versionid bigger than the bigest one in db"
	errorMsg[EC_SERVICEPAGEINFO_BODY_MISSING] = "body is missing"
	errorMsg[EC_SERVICEPAGEINFO_DELETE_INVALID_SID] = "invalid param sid"
	errorMsg[EC_SERVICEPAGEINFO_SID_MISSING] = "sid is missing"
	errorMsg[EC_SERVICEPAGEINFO_GET_INVALID_BODY] = "invalid param body, can't parse body"
	errorMsg[EC_SERVICEPAGEINFO_GET_MAX_VERSIONID_ERR] = "get maxVersionid err"
	errorMsg[EC_SERVICEPAGEINFO_NO_DATA_IN_DB] = "no data in db"

	errorMsg[EC_INVALID_TICK] = "tick is wrong, publishTick should be no bigger than endTick or else"
	errorMsg[EC_HOTACTIVITY_AID_MISSING] = "invalid body param, activity_id is missing"

	errorMsg[EC_HOTACTIVITY_ACTIVITYID_NOMATCH] = "no such activityid in memory cache!"

	errorMsg[EC_ADVERTOPER_POSITION_INVALID] = "invalid position"

}

func Msg(errcode uint) string {
	if msg, ok := errorMsg[errcode]; ok {
		return msg
	}
	return ""
}
